#pragma once
#include <mutex>
#include <condition_variable>

class Semaphore
{
private:
    std::mutex mtx;
    std::condition_variable cv;
    bool ready = false;

public:
    Semaphore() {}
    ~Semaphore() {}

    void wait_for_signal()
    {
        std::unique_lock<std::mutex> lock(mtx);
        cv.wait(lock, [this]
                { return ready; });
        ready = false;
    }

    void send_signal()
    {
        std::unique_lock<std::mutex> lock(mtx);
        ready = true;
        cv.notify_all();
    }
};
